package com.weather.web.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weather.common.annotation.Log;
import com.weather.common.core.controller.BaseController;
import com.weather.common.core.domain.AjaxResult;
import com.weather.common.enums.BusinessType;
import com.weather.business.domain.NmRule;
import com.weather.business.service.INmRuleService;
import com.weather.common.utils.poi.ExcelUtil;
import com.weather.common.core.page.TableDataInfo;

/**
 * 气象建议规则Controller
 *
 * @author ruoyi
 * @date 2024-03-16
 */
@RestController
@RequestMapping("/business/rule")
public class NmRuleController extends BaseController
{
    @Autowired
    private INmRuleService nmRuleService;

    /**
     * 查询气象建议规则列表
     */
    @PreAuthorize("@ss.hasPermi('business:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(NmRule nmRule)
    {
        startPage();
        List<NmRule> list = nmRuleService.selectNmRuleList(nmRule);
        return getDataTable(list);
    }

    /**
     * 导出气象建议规则列表
     */
    @PreAuthorize("@ss.hasPermi('business:rule:export')")
    @Log(title = "气象建议规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NmRule nmRule)
    {
        List<NmRule> list = nmRuleService.selectNmRuleList(nmRule);
        ExcelUtil<NmRule> util = new ExcelUtil<NmRule>(NmRule.class);
        util.exportExcel(response, list, "气象建议规则数据");
    }

    /**
     * 获取气象建议规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(nmRuleService.selectNmRuleById(id));
    }

    /**
     * 新增气象建议规则
     */
    @PreAuthorize("@ss.hasPermi('business:rule:add')")
    @Log(title = "气象建议规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NmRule nmRule)
    {
        return toAjax(nmRuleService.insertNmRule(nmRule));
    }

    /**
     * 修改气象建议规则
     */
    @PreAuthorize("@ss.hasPermi('business:rule:edit')")
    @Log(title = "气象建议规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NmRule nmRule)
    {
        return toAjax(nmRuleService.updateNmRule(nmRule));
    }

    /**
     * 删除气象建议规则
     */
    @PreAuthorize("@ss.hasPermi('business:rule:remove')")
    @Log(title = "气象建议规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nmRuleService.deleteNmRuleByIds(ids));
    }
}
